//使用函数对象存储
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
template <typename T>
struct DisplayContent
{
    int counter;
    DisplayContent()
    {
        counter = 0;
    };
    void operator()(const T& Element)
    {
        cout << Element << endl;
        counter ++;
    }
};

int main(int argc, char const *argv[])
{
    /* code */
    list<int>mylist;
    for(int i = 0; i < 9; i++)
    {
        mylist.push_back(i);
    }
    DisplayContent<int>result;
    result = for_each(mylist.begin(), mylist.end(), DisplayContent<int>());
    cout << "Total:" << result.counter << endl;
    return 0;
}
